<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function fn(s) {
      const res = [], path = [];
      backtracking(0, 0)
      return res;
      function backtracking(i) {
        const len = path.length;
        if (len > 4) return;
        if (len === 4 && i === s.length) {
          res.push(path.join("."));
          return;
        }
        for (let j = i; j < s.length; j++) {
          const str = s.slice(i, j + 1);
          if (str.length > 3 || +str > 255) break;
          if (str.length > 1 && str[0] === "0") break;
          path.push(str);
          backtracking(j + 1);
          path.pop()
        }
      }
    };
    console.log(fn("25525511135"));
  </script>
</body>

</html>